;;; Declarations

(deftemplate person
   (slot name)
   (slot has-been-arrested)
   (slot is-trustworthy))

(deftemplate innocent-person
   (slot name))

(deftemplate guilty-person
   (slot name))

(deftemplate suspected-person
   (slot name))

(deftemplate alibi
   (slot of)
   (slot confirmed-by))

;;; Production rules

(defrule suspect-rule
   (person (name ?x) (has-been-arrested yes))
   (not (innocent-person (name ?x)))
   =>
   (assert (suspected-person (name ?x))))

(defrule innocent-rule
   (alibi (of ?x) (confirmed-by ?y))
   (person (name ?y) (is-trustworthy yes))
   =>
   (assert (innocent-person (name ?x))))

(defrule innocent-elimination
	 (innocent-person (name ?x))
	 ?rule <- (suspected-person (name ?x))
	 =>
	 (retract ?rule))

(defrule innocent-elimination-2
	 (innocent-person (name ?x))
	 ?rule <- (guilty-person (name ?x))
	 =>
	 (retract ?rule))

(defrule guilty-rule
   (suspected-person (name ?x))
   =>
   (assert (guilty-person (name ?x))))

(assert (alibi (of Mohammed) (confirmed-by John)))
(assert (person (name John) (is-trustworthy yes)))
(assert (person (name Mohammed) (has-been-arrested yes)))

(run)
(facts)
